package com.uenpay.im.ui.old.activity.chat;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import com.uenpay.im.BroadcastAction;
import com.uenpay.im.IMApplication;
import com.uenpay.im.R;

/**
 * @author SL
 * @created 2016-2-29 16:00:49
 * @copyRight http://www.qiyunxin.com
 * @function 撤销消息loading
 */
public class DialogLoadingActivity extends Activity {

	private CloseDialogLoadingBr mCloseDialogLoadingBr = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		IMApplication.getInstance().addActivity(this);
		setContentView(R.layout.activity_dialog_loading_layout);
		initView();
	}

	private void initView() {
	}

	@Override
	protected void onResume() {
		if (mCloseDialogLoadingBr == null) {
			mCloseDialogLoadingBr = new CloseDialogLoadingBr();
			IntentFilter filter = new IntentFilter(
					BroadcastAction.ACTION_CLOSE_DIALOG_LOADING_ACTIVITY);
			registerReceiver(mCloseDialogLoadingBr, filter);
		}
		super.onResume();
	}

	private class CloseDialogLoadingBr extends BroadcastReceiver {

		@Override
		public void onReceive(Context arg0, Intent arg1) {
			if (arg1.getAction().equals(
					BroadcastAction.ACTION_CLOSE_DIALOG_LOADING_ACTIVITY)) {
				finish();
			}
		}

	};

	@Override
	public void onBackPressed() {
		finish();
	}

	@Override
	protected void onDestroy() {
		IMApplication.getInstance().removeActivity(this);
		if (mCloseDialogLoadingBr != null) {
			unregisterReceiver(mCloseDialogLoadingBr);
		}
		super.onDestroy();
	}
}
